var comm = {};
comm.util = {};

comm.util.makeCombobox = function(result, objid, choiceString, selected) {
	var selectObj = document.createElement("select");
	selectObj.id = objid;
	var json = eval('(' + result + ')');
	var optObj;
	if ( json == "" ){
		optObj = new Option(choiceString,"");
		optObj.text = choiceString; 
		optObj.value = "";
		selectObj.add(optObj);
	} else {
		optObj = document.createElement('OPTION');
		optObj.text = choiceString; 
		optObj.value = ""; 
	}
	selectObj.add(optObj); 
	
	var jsonCnt = json.items.length;
	for(var i=0; i< jsonCnt; i++){
		optObj = document.createElement('OPTION');
		if(json == null || json.items[i] == null || json.items[i].key == undefined || json.items[i].key == "") continue;
		optObj.text = json.items[i].key; 
		optObj.value = json.items[i].value; 
		if(json.items[i].value == selected) optObj.selected = true;
		selectObj.add(optObj); 
	}
	
	return selectObj;
};


comm.util.addCombobox = function(result, objid, choiceString, selected) {
	var json = eval('(' + result + ')');
	for(var i= document.getElementById(objid).options.length ; i>=0 ; i--){
		document.getElementById(objid).options[i]=null;
	}
	
	var optObj;
	if ( json == "" ){
		optObj = new Option(choiceString,"");
		optObj.text = choiceString; 
		optObj.value = "";
		document.getElementById(objid).add(optObj);
	} else {
		optObj = document.createElement('OPTION');
		optObj.text = choiceString; 
		optObj.value = ""; 
	}
	document.getElementById(objid).add(optObj); 
	
	var jsonCnt = json.items.length;
	for(i=0; i< jsonCnt; i++){
		optObj = document.createElement('OPTION');
		if(json == null || json.items[i] == null || json.items[i].key == undefined || json.items[i].key == "") continue;
		optObj.text = json.items[i].key; 
		optObj.value = json.items[i].value; 
		if(json.items[i].value == selected) optObj.selected = true;
		document.getElementById(objid).add(optObj); 
	}
};

